import { ICmpnt, EnumAction, IBindEvent } from "xcore/cmpnt"
import { bindDialog, removeDialog } from "./dialog"
import { bindForm, removeForm } from "./form"

export function bindEvent(cmpnt: ICmpnt, event: IBindEvent): ICmpnt | undefined {
    switch (event.action) {
        case EnumAction.Dilog:
            return bindDialog(cmpnt, event)
        case EnumAction.FormSubmit:
            return bindForm(cmpnt, event)
        default:
            throw new Error(`${event.action} 不支持`)
    }
}
export function removeEvent(cmpnt: ICmpnt, event: IBindEvent): void {
    switch (event.action) {
        case EnumAction.Dilog:
            removeDialog(cmpnt, event)
            break;
        case EnumAction.FormSubmit:
            removeForm(cmpnt, event)
            break;
        default:
            throw new Error(`${event.action} 不支持remove`)
    }
}